package com.ziyucoding.springboot.labs.lab4.concurrentdemo.example.immutable;

import com.google.common.collect.ImmutableMap;
import com.ziyucoding.springboot.labs.lab4.concurrentdemo.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;


/**
 * 不可变对象示例2
 *
 * @author ziyucoding
 * @date 2022-11-27
 **/
@Slf4j
@ThreadSafe
public class ImmutableExample3 {

    private static ImmutableMap<String, String> companyNameMap = ImmutableMap.<String, String>builder()
            .put("apple", "苹果").put("google", "谷歌").build();

    public static void main(String[] args) {
        log.info("{}", companyNameMap.get("apple"));
        companyNameMap.put("jd", "京东");
        // 抛出异常 java.lang.UnsupportedOperationException
        log.info("{}", companyNameMap.get("apple"));
    }
}
